<?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    /**
     * Controls data flow from website and rest services
     * 
     * NOTES:
     * 
     * Variables:
     * $session  is created in "template" library - used in view's
     */
    class Hotels extends CI_Controller {

        private $data;
        private $filters_count = array(
            'filter_price' => array(),
            'filter_class' => array(
                'class-1' => 0,
                'class-2' => 0,
                'class-3' => 0,
                'class-4' => 0,
                'class-5' => 0,
                'class-0' => 0
            ),
            'hotel_type' => array(
                'hotel' => 0,
                'apartment' => 0,
                'villa' => 0
            ),
            'filter_facilities' => array()
        );

        function __construct() {

            parent::__construct();

//            $this->output->enable_profiler(TRUE);
//
//            $this->benchmark->mark('code_start');

            $this->load->library('rest', array(
                'server' => REST_URL_HOTELS,
                'http_user' => 'cipa',
                'http_pass' => 'booking',
                'http_auth' => 'basic' // or 'digest' 
            ));

            $this->data['host_url'] = HOST_URL_HOTELS;

            require_once("urlify.php");
            $this->load->library('session');
            $this->load->library('template');
            $this->load->helper('urlify');
            $this->load->helper('gallery');
            $this->load->helper('clean_html');
            $this->load->helper('language');
            $this->load->helper('inflector');
            $this->lang->load('score');
            $this->lang->load('excursions');
            $this->lang->load('rentacar');
            $this->lang->load('common');
            $this->lang->load('hotels');
            $this->template->set_view("hotels");

            $home_input = array('specialHotels', 'recommended', 'googlemap');

            // Do caching
            $this->load->driver('cache', array('adapter' => 'file')); // za uklucuvanje na kes mogucnosti

            $cache_file = $this->crate_cache_filename(array('lang' => $this->lang->lang()), 'combined');
            if (!$combined = $this->cache->get($cache_file)) {
                $combined = $this->rest->post(
                        'home', array('lang' => $this->lang->lang(), 'input' => $home_input));
                $this->cache->save($cache_file, $combined, 300);
            }
            //$this->firephp->log ( $combined );

            if ($combined):

                $this->data['action_1'] = $combined->recommended;
                $this->data['action_2'] = $combined->specialHotels;
                $this->data['gmap_hotels'] = $combined->googlemap;

                //$this->firephp->log($combined->special_offer->objects);

                shuffle($this->data['action_1']);
                shuffle($this->data['action_2']);

            endif;


            // Call To Rest Server For All Destinations
            $cache_file = $this->crate_cache_filename(array('lang' => $this->lang->lang()), 'destinationList');
            if (!$this->data['destinations'] = $this->cache->get($cache_file)) {
                $this->data['destinations'] = $this->rest->post(
                        'destinationList', array('lang' => $this->lang->lang()));
                $this->cache->save($cache_file, $this->data['destinations'], 300);
            }

            // Call To Rest Server For DestinationDetials
            $cache_file = $this->crate_cache_filename(array('lang' => $this->lang->lang()), 'destinationDetails');
            if (!$this->data['destination'] = $this->cache->get($cache_file)) {
                $this->data['destination'] = $this->rest->post(
                        'destinationDetails', array(
                    'lang' => $this->lang->lang(),
                    'destination_id' => 51, // Dures Albania
                ));
                $this->cache->save($cache_file, $this->data['destination'], 300);
            }

            //$this->firephp->log($this->data['destination']);

            define('DEBUG_SESSION', FALSE);
        }

        public function index() {

            $this->session->sess_destroy();
            if ($this->session->userdata('my_data')):
                $this->session->set_userdata('my_data', NULL);
            endif;

            $this->data['title'] = lang('title-home');
            $this->data['description'] = lang('description-home');

            //$this->firephp->log($this->data);

            $rest_data = array(
                "name_startsWith" => '',
                "lang" => $this->lang->lang()
            );

            $this->data['destinations'] = $this->rest->post(
                    'destinationList', array('lang' => $this->lang->lang()));

            $this->_debug_session();
            //$this->benchmark->mark('code_end');
            //$this->firephp->log ( $this->benchmark->elapsed_time ( 'code_start', 'code_end' ) );
            $this->template->load('hotels/home', $this->data);
        }

        private function _loadFilter() {

            loadJoinedGroupsAttributes($this->data['objects']);

            $this->data['items'] = json_encode($this->data['objects']);
            $this->data['unique'] = findUniqueMakeCount($this->data['objects']); // find unique filter attributes
            $this->data['unique_prices'] = findUniquePricesMakeCount($this->data['objects'], isset($_GET['non_specific_dates'])); // find unique prices for filter
            $this->data['unique_stars'] = findUniqueStarsMakeCount($this->data['objects']); // find unique stars for filter
            // sort, splice and shuffle facilities & services
            sort_attributes($this->data['unique']);
            if (count($this->data['unique']) > 23)
                array_splice($this->data['unique'], 23);

            shuffle($this->data['unique']);

            // sort stars array
            ksort($this->data['unique_stars']);

            // Load Acc Type
            $this->data['unique_acc_type'] = findUniqueAccType($this->data['objects']);
        }

        /**
         * 
         * $_GET
         * 
         * dest_hot              :String
         * check_in              :Date
         * check_out             :Date
         * nr_adults             :Integer
         * nr_childrens          :Integer
         * ages                  :Array
         * non_specific_dates    :Boolean
         * 
         */
        public function search() {

            $this->data['title'] = lang('title-search');
            $this->data['description'] = lang('description-search');
            $this->data['canonical'] = 'http://globtour.me/' . $this->lang->lang() . '/hotels/search?dest_hot=&non_specific_dates=1';


            $_GET['dest_hot'] = trim($_GET['dest_hot']);

            // no dates specified, just serach object based on destination/hotel
            if (isset($_GET['non_specific_dates'])):

                $rest_data = array(
                    "dest_hot" => $_GET['dest_hot'],
                    "lang" => $this->lang->lang(),
                );

                if (isset($_GET['sort_by'])):
                    $rest_data['sort_by'] = $_GET['sort_by'];

                endif;

                cleanup_GET_array();

                $cache_file = $this->crate_cache_filename($rest_data, 'search_preview');

                if (!$this->data['objects'] = $this->cache->get($cache_file)) {
                    //$this->firephp->log ( $cache_file );
                    $this->data['objects'] = $this->rest->post("searchPreview", $rest_data);

                    //$this->firephp->log ( $this->data['objects'] );
                    $this->cache->save($cache_file, $this->data['objects'], 300);
                }

                // Broese all accommodation
                if ($_GET['dest_hot'] == 'browse')
                    $_GET['dest_hot'] = "";

                $this->session->set_userdata('my_data', $_GET);

                $this->_loadFilter();

                $this->template->load('hotels/search', $this->data);
                // remove checkin, checkout, set nradults, nrchildrens

                $this->_debug_session();
                return;

            endif; // end no specific dates
            //
            // dates are submited, preform search 
            cleanup_GET_array();
            $rest_data = $_GET;
            $rest_data['lang'] = $this->lang->lang();

            $cache_file = $this->crate_cache_filename($rest_data, 'search');

            if (!$this->data['objects'] = $this->cache->get($cache_file)) {
                //$this->firephp->log ( $cache_file );
                $this->data['objects'] = $this->rest->post("search", $rest_data);
                $this->cache->save($cache_file, $this->data['objects'], 300);
            }

            $this->session->set_userdata('my_data', $_GET);

            $this->_loadFilter();

//            $this->firephp->log($this->data);

            $this->_debug_session();
            $this->template->load('hotels/search', $this->data);
        }

        public function crate_cache_filename($data, $mehod) {
            $filename = 'hotels_' . $mehod . '';

            foreach ($data as $key => $value):
                if (is_array($value)) {
                    foreach ($value as $value) {
                        $filename.='_' . $key . '-' . $value;
                    }
                } else {
                    $filename.='_' . $key . '-' . $value;
                }
            endforeach;

            return $filename;
        }

        /**
         * $_GET
         * 
         * dest_hot              :String
         * object_type           :String
         */
        public function popular() {

            $this->data['title'] = lang('title-search');
            $this->data['description'] = lang('description-search');
            $this->data['canonical'] = 'http://globtour.me/' . $this->lang->lang() . '/hotels/search?dest_hot=&non_specific_dates=1';



            $_GET['dest_hot'] = trim($_GET['dest_hot']);

            $rest_data = array(
                "dest_hot" => $_GET['dest_hot'],
                "lang" => $this->lang->lang()
            );

            if (isset($_GET['object_type'])):
                $rest_data['object_type'] = $_GET['object_type'];
            endif;

            if (isset($_GET['sort_by'])):
                $rest_data['sort_by'] = $_GET['sort_by'];

            endif;

            $this->data['objects'] = $this->rest->post("search_preview", $rest_data);

            //$this->firephp->log($this->data['objects']);

            $this->session->set_userdata('my_data', $_GET);

            $this->_do_find_facilities_filters($this->data['objects']);
            $this->_do_filters_count($this->data['objects']);
            $this->data['filters_count'] = $this->filters_count;
            $this->data['objects'] = $this->_do_filter($this->data['objects']);

            $this->_debug_session();
            $this->template->load('booking/hotels-list', $this->data);
        }

        /**
         * 
         * $_GET
         * 
         * dest_hot              :String
         * check_in              :Date
         * check_out             :Date
         * nr_adults             :Integer
         * nr_childrens          :Integer
         * ages                  :Array
         * non_specific_dates    :Boolean
         * object_type           :String
         * sort_by               :String
         * 
         */
        public function sort_hotels() {

            // We do check if my_data['check_in'] is set in session
            // if so, we sort from search, if not, we sort from serch_preview
            $my_data = $this->session->userdata('my_data');

            if (isset($my_data['check_in'])) {
                redirect(base_url('search?' . http_build_query($_GET)));
            } else {
                redirect(base_url('popular?' . http_build_query($_GET)));
            }
        }

        /**
         * 
         * $_GET
         * 
         * hotel_id              :Integer
         * 
         */
        public function details_preview() {
            if (isset($_GET['dest_hot']))
                $_GET['dest_hot'] = trim($_GET['dest_hot']);


            $rest_data = array(
                "hotel_id" => $_GET['hotel_id'],
                "lang" => $this->lang->lang()
            );

            $this->data['object'] = $this->rest->post("detailsPreview", $rest_data);
            $_GET['dest_hot'] = $this->data['object']->object_name;
            $this->data['title'] = str_replace('{|0|}', $this->data['object']->object_name, lang('title-details'));
            $this->data['description'] = clean_html($this->data['object']->object_address);
            $this->data['canonical'] = 'http://globtour.me/' . $this->lang->lang() . '/hotels/hotels/details_preview?hotel_id=' . $this->data['object']->object_ID;

            $this->session->set_userdata('my_data', $_GET);

            //$this->firephp->log($this->data['object']);
            $this->_debug_session();
            $this->template->load('hotels/details', $this->data);
        }

        /**
         * 
         * $_GET
         * 
         * dest_hot              :String
         * check_in              :Date
         * check_out             :Date
         * nr_adults             :Integer
         * nr_childrens          :Integer
         * ages                  :Array
         * non_specific_dates    :Boolean
         * 
         */
        public function details() {

            // dates are submited, preform search 
            cleanup_GET_array();

            $rest_data = $_GET;
            $rest_data['lang'] = $this->lang->lang();

            $this->data['object'] = $this->rest->post("details", $rest_data);

            //$this->firephp->log($this->data['object']);

            $_GET['dest_hot'] = $this->data['object']->object_name;
            $this->data['title'] = str_replace('{|0|}', $this->data['object']->object_name, lang('title-details'));
            $this->data['description'] = clean_html($this->data['object']->object_address);
            $this->data['canonical'] = 'http://globtour.me/' . $this->lang->lang() . '/hotels/hotels/details_preview?hotel_id=' . $this->data['object']->object_ID;

            $this->session->set_userdata('my_data', $_GET);

            $this->_debug_session();
            $this->template->load('hotels/details', $this->data);
        }

        /**
         *
         * $_GET
         *
         * dest_hot              :String
         * object_id             :Integer
         * room_id               :Integer
         * check_in              :Date
         * check_out             :Date
         * nr_adults             :Integer
         * nr_childrens          :Integer
         * ages                  :Array
         *
         */
        public function checkout() {

            if (isset($_GET['dest_hot']))
                unset($_GET['dest_hot']);
            $this->session->set_userdata('my_data', $_GET);

            $rest_data = $_GET;
            $rest_data['lang'] = $this->lang->lang();
            $this->data['object'] = $this->rest->post("customerForm", $rest_data);

            //$this->firephp->log ( $this->data['object'] );
            $this->data['title'] = "Checkout - " . $this->data['object']->object_name;


            $this->template->load('hotels/checkout', $this->data);
        }

        public function checkout_customer() {

            //$this->firephp->log($_POST);


            $booking = $this->rest->post('createReservation', $_POST);
            //
            //check if booking is insert in db
            if (isset($booking->reservation_id)) {

                echo json_encode(array('response' => TRUE, 'msg' => 'OK', 'json' => $booking));
            } else {

                echo json_encode(array('response' => FALSE, 'msg' => $booking));
            }
        }

        public function checkout_show_order($orderID) {

            $this->data['title'] = "Booking Information";

            $params = array(
                'reservation_id' => $orderID,
                'lang' => $this->lang->lang()
            );

            $this->data['order'] = $this->rest->post('showReservationInfo', $params);

            //$this->firephp->log($this->data['order']);

            $this->template->load('hotels/checkout_3', $this->data);
        }

        public function reservation_cancellation() {

            $this->data['title'] = "Reservation Cancellation";
            $this->data['reservation_ID'] = $this->input->get('reservation_ID');
            $this->_debug_session();
            $this->template->load('hotels/parts/reservation/cancel', $this->data);
        }

        public function cancellation_confirmation() {

            $this->data['title'] = "Cancellation Confirmation";
            $this->data['reservation_ID'] = $this->input->get('reservation_ID');
            $result = $this->rest->post("reservation_cancellation", array('reservation_ID' => $this->data['reservation_ID']));
            $this->_debug_session();
            $this->template->load('hotels/parts/reservation/cancellation_confirmation', $this->data);
        }

        public function hotel_details_map($object_ID) {
            //$object_ID=$this->security->xss_clean($object_ID);

            $rest_data = array(
                "hotel_id" => $object_ID
            );

            $data['hotel'] = $this->rest->post("details_preview", $rest_data);

            //$this->firephp->log($data['hotel']);

            $html = $this->load->view('layouts/google_object', $data, TRUE);
            $this->_debug_session();
            echo json_encode(
                    array('action' => true,
                        'html' => $html
            ));
        }

        /**
         * 
         * $_GET
         * 
         * dest_hot              :String
         * check_in              :Date
         * check_out             :Date
         * nr_adults             :Integer
         * nr_childrens          :Integer
         * ages                  :Array
         * non_specific_dates    :Boolean
         * 
         */
        public function search_google_object($object_ID) {
            $this->session->set_userdata('my_data', $_GET);
            $my_data = $this->session->userdata('my_data');

            if (!$my_data) {
                $this->_debug_session();
                echo json_encode(
                        array('action' => false,
                            'msg' => 'session_expired'
                ));
                return;
            }

            $my_data['hotel_id'] = $object_ID;

            //$this->firephp->log($my_data);
            // $this->data['hotel'] = $this->rest->post ( "search", $my_data );
            $this->data['hotel'] = $this->rest->post("details", $my_data);


            //$this->firephp->log ( $this->data['hotel'] );

            $html = $this->load->view('layout/google_object', $this->data, TRUE);

            //echo $html;

            $this->_debug_session();
            echo json_encode(
                    array('action' => true,
                        'html' => $html
            ));
        }

        public function search_preview_google_object($object_ID) {

            // Fix for homepage google map preview
            if (empty($_GET)):
                $_GET['dest_hot'] = "";
            endif;

            $this->session->set_userdata('my_data', $_GET);
            $my_data = $this->session->userdata('my_data');

            if (!$my_data) {
                $this->_debug_session();
                echo json_encode(
                        array('action' => false,
                            'msg' => 'session_expired'
                ));
                return;
            }

            $rest_data = array(
                "dest_hot" => $my_data['dest_hot'],
                "hotel_id" => $object_ID
            );

            //$this->firephp->log($rest_data);
            //$this->data['hotel'] = $this->rest->post ( "search_preview", $rest_data );
            $this->data['hotel'] = $this->rest->post("detailsPreview", $rest_data);

            //$this->firephp->log ( $this->data['hotel'] );

            $html = $this->load->view('layout/google_object', $this->data, TRUE);

            //echo $html;

            $this->_debug_session();
            echo json_encode(
                    array('action' => true,
                        'html' => $html
            ));
        }

        private function _debug_session() {
            if (DEBUG_SESSION):

                $data = $this->session->userdata('my_data');

                if (!$data) {
                    $this->firephp->log('my_data is: empty');
                } else {
                    $this->firephp->log('my_data is:');
                    $this->firephp->log($this->session->userdata('my_data'));
                }

            endif;
        }

        private function _do_filter($objects) {

            $filters = array(
                'filter_price' => 'rooms',
                'filter_facilities' => 'facilities',
                'filter_class' => 'object_number_of_stars',
                'hoteltype' => 'object_type_type'
            );

            // check if ajax filters
            if (isset($_GET['ajax_filter'])):

                //
                // go troug each filter type
                foreach ($filters as $filter => $object_field):

                    //$this->firephp->log($filter);
                    // check if that type is submites
                    if (isset($_GET[$filter])):



                        //$this->firephp->log($filter);

                        switch ($filter):

                            case 'filter_class':

                                // do something
                                //$this->firephp->log($_GET[$filter]);

                                $cnt = count($objects);

                                for ($i = 0; $i < $cnt; $i++):

                                    $to_compare_stars = $objects[$i]->object_number_of_stars;
                                    if ($to_compare_stars == "")
                                        $to_compare_stars = 0;

                                    if (in_array('class-' . $to_compare_stars, $_GET[$filter])) {
                                        //$this->firephp->log($objects[$i]->object_type_type.' is included in filters');
                                    } else {
                                        //$this->firephp->log($objects[$i]->object_type_type.' is not included in filters');
                                        unset($objects[$i]);
                                    }



                                endfor;

                                $objects = array_values($objects);

                                //$this->firephp->log('Count afther filter_class:'.count($objects));

                                break;

                            case 'hoteltype':

                                // do something
                                //$this->firephp->log($_GET[$filter]);

                                $cnt = count($objects);

                                for ($i = 0; $i < $cnt; $i++):

                                    if (in_array($objects[$i]->object_type_type, $_GET[$filter])) {
                                        //$this->firephp->log($objects[$i]->object_type_type.' is included in filters');
                                    } else {
                                        //$this->firephp->log($objects[$i]->object_type_type.' is not included in filters');
                                        unset($objects[$i]);
                                    }



                                endfor;

                                $objects = array_values($objects);

                                //$this->firephp->log('Count afther hoteltype:'.count($objects));

                                break;

                            case 'filter_facilities':

                                $cnt = count($objects);
                                for ($i = 0; $i < $cnt; $i++):

                                    $objects[$i]->facility = array();

                                    // do create clean facility array
                                    foreach ($objects[$i]->facilities as $group):

                                        if (!empty($group)):

                                            foreach ($group as $key => $attribute):

                                                //$this->firephp->log($key);
                                                //$attribute=trim($attribute);

                                                $objects[$i]->facility[$key] = 1;

                                            endforeach;

                                        endif;

                                    endforeach;

                                    // if empty facilities, nothing to search, do remove object
                                    if (empty($objects[$i]->facility))
                                        unset($objects[$i]);

                                endfor;

                                $objects = array_values($objects);

                                // do filter
                                $cnt = count($objects);
                                for ($i = 0; $i < $cnt; $i++):

                                    $found = 1;


                                    foreach ($_GET[$filter] as $key => $value):

                                        //$this->firephp->log($objects[$i]->facility);

                                        if (!array_key_exists($value, $objects[$i]->facility)) {
                                            $found = 0;
                                            //$this->firephp->log('found:'.$value);
                                        }

                                    endforeach;


                                    if ($found == 0)
                                        unset($objects[$i]);

                                endfor;

                                $objects = array_values($objects);



                                break;

                            case 'filter_price':

                                //$this->firephp->log('filter_price');
                                // do something
                                //get filters

                                $filters = array();

                                foreach ($_GET[$filter] as $filter):

                                    $pieces = explode('_', $filter);

                                    array_push($filters, array(
                                        'from' => $pieces[1],
                                        'to' => $pieces[2] == -1 ? 999999 : $pieces[2],
                                    ));

                                endforeach;

                                //$this->firephp->log($filters);
                                // go troug each filter and do remove rooms that do not fit between

                                foreach ($filters as $value):

                                    //$this->firephp->log($value['from'].' - '.$value['to']);

                                    $cnt = count($objects);

                                    for ($i = 0; $i < $cnt; $i++): // go troug each object

                                        $rooms = $objects[$i]->rooms;

                                        $cnt_rooms = count($rooms);
                                        $found = 0;

                                        for ($j = 0; $j < $cnt_rooms; $j++): // go troug each room

                                            $price = $rooms[$j]->selling_total;

                                            if ($price >= $value['from'] && $price < $value['to']):
                                                //$this->firephp->log("Price ".$price.' is between '.$value['from'].' and '.$value['to'].'. Hotel '.$objects[$i]->object_name);
                                                $found = 1;
                                            endif;
                                            {
                                                
                                            }

                                        endfor;

                                        if ($found == 0):
                                            unset($objects[$i]);

                                        endif;

                                    endfor;

                                    $objects = array_values($objects);


                                endforeach;

                                break;

                        endswitch;




                    endif;



                endforeach;


            endif;

            //$this->firephp->log($objects);
            return $objects;
        }

        private function _do_filters_count($objects) {
            foreach ($objects as $hotel):

                // Star rating
                //$this->firephp->log($hotel->object_number_of_stars);
                if ($hotel->object_number_of_stars == "") {
                    $this->filters_count['filter_class']['class-0']++;
                } else {
                    $this->filters_count['filter_class']['class-' . (int) $hotel->object_number_of_stars]++;
                }
                //filter_class
                // Hotel Type

                $this->filters_count['hotel_type'][$hotel->object_type_type]++;

            endforeach;
        }

        private function _do_find_facilities_filters($objects) {


            $filter_facilities = array();

            foreach ($objects as $hotel):

                $facilities = $hotel->facilities;

                // Ovdje cemo kreirati niz na nivou objekta za jedinstvenu provjeru atributa
                $unique_attribute = array();


                foreach ($facilities as $group):
                    if (!empty($group)) {
                        foreach ($group as $key => $attribute):

                            //$this->firephp->log($key);
                            //$attribute=trim($attribute);

                            if (!in_array($key, $unique_attribute)):
                                $unique_attribute[].=$key;




                                if (isset($filter_facilities[$key])) {
                                    $filter_facilities[$key]->cnt++;
                                } else {
                                    $filterSTD = new stdClass;
                                    $filterSTD->title = $attribute;
                                    $filterSTD->cnt = 1;
                                    //$filter_facilities[$key]=1;
                                    $filter_facilities[$key] = $filterSTD;
                                }



                            endif;



                        endforeach;
                    }
                endforeach;

            endforeach;

            $final_array = $filter_facilities;

            $filter_facilities = $this->_sort_me($filter_facilities);



            if (count($filter_facilities) > 17) {
                array_splice($filter_facilities, 17);
            }

            // Ovo sluzi za sminku
            foreach ($final_array as $attr => $key):

                if (!array_key_exists($attr, $filter_facilities)):
                    unset($final_array[$attr]);
                endif;
            //$i++;
            endforeach;

            //return $final_array;
            $this->filters_count['filter_facilities'] = $final_array;
        }

        private function _sort_me($facilities) {
            $sorted = array();

            $cnt = count($facilities);
            $i = 0;
            foreach ($facilities as $key1 => $std1):

                $sorted[$i] = $std1;
                $sorted[$i]->key = $key1;

                $j = 0;
                foreach ($facilities as $key2 => $std2):

                    if ($j > $i):
                        if ($std2->cnt > $sorted[$i]->cnt):
                            $sorted[$i] = $std2;
                            $sorted[$i]->key = $key2;
                        endif;
                    endif;

                    $j++;

                endforeach;

                $i++;

            endforeach;

            $cnt2 = count($sorted);
            $final_sorted = array();

            // Mama mia
            for ($i = 0; $i < $cnt2; $i++):

                $final_sorted[$sorted[$i]->key] = $facilities[$sorted[$i]->key];

            endfor;

            return $final_sorted;
        }

        public function destinations_hotels_JSON() {

            $rest_data = array(
                "name_startsWith" => $_GET['name_startsWith'],
                "lang" => $this->lang->lang()
            );

            $items = $this->rest->post("destinationsHotelsAutocomplete", $rest_data);

            //echo JSON to page  
            $response = $_GET["callback"] . "(" . json_encode(array('items' => $items)) . ")";

            echo $response;
        }

        public function submit_review() {

            $rest_data = $_GET;

            $success = $this->rest->post("submit_review", $rest_data);

            echo json_encode(array(
                'success' => $success
            ));
        }

    }

?>